import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { ApiProvider } from '../../providers/api/api'
import { Md5 } from 'ts-md5/dist/md5';
import { Storage } from '@ionic/storage';


/**
 * Generated class for the UserAgentPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
	selector: 'page-user-agent',
	templateUrl: 'user-agent.html',
})
export class UserAgentPage {
	public uid: any;
	public resData: any = {};
	public agentMes: any = {};


	constructor(
		public navCtrl: NavController, 
		public navParams: NavParams,
		public Api: ApiProvider,
        public storage: Storage ) {

			storage.get('userId').then(
                (value: string) => {
                    this.uid = value
                }
            );

	}

    ionViewDidEnter(){
		console.log('ionViewDidEnter UserAgentPage');
		this.PostAgent();
	}

	PostAgent(){
		let timeStamp = (new Date()).getTime();
		if( this.uid ) {
			this.Api.agent({
				times: timeStamp,
				token: Md5.hashStr('HalfPriceMall' + timeStamp),
				id: this.uid
			}).then(res=>{
				this.resData = res;
				if( this.resData.code == 1 ) {
					this.agentMes =  this.resData.data;
				}
			})
		}
	}

	datail(i){
		this.navCtrl.push('UserAgentDetailPage',{
			index: i
		})
	}

}
